package com.aaa.stock.service.prov.impl;

import com.aaa.entity.Producer;
import com.aaa.entity.Provider;
import com.aaa.stock.dao.prov.ProviderDao;
import com.aaa.stock.service.prov.ProviderService;
import com.aaa.stock.vo.ProvdierVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
public class ProviderServiceImpl extends ServiceImpl<ProviderDao,Provider> implements ProviderService {
    @Autowired
    private ProviderDao providerDao;

    @Override
    public Result<IPage<Provider>> findByListtion(Integer currentPage, Integer pageSize, ProvdierVo provdierVo) {
        IPage<Provider> page=new Page<>(currentPage,pageSize);
        QueryWrapper<Provider> wrapper=new QueryWrapper<>();
        if(StringUtils.hasText(provdierVo.getProviderName())){
            wrapper.like("provider_name",provdierVo.getProviderName());
        }
        if(StringUtils.hasText(provdierVo.getContactName())){
            wrapper.like("contact_name",provdierVo.getContactName());
        }
        if(Objects.nonNull(provdierVo.getContactTel())){
            wrapper.eq("contact_tel",provdierVo.getContactTel());
        }
        if(Objects.nonNull(provdierVo.getStatus())){
            wrapper.eq("status",provdierVo.getStatus());
        }

        IPage<Provider> page1 = providerDao.selectPage(page, wrapper);
        return new Result<IPage<Provider>>(2000,"查询厂家成功",page1);
    }

    @Override
    public Result<Map<String, Object>> deleteProv(Long providerIds) {
        providerDao.deleteProv(providerIds);
        return new Result<>(2000,"删除成功");
    }

    @Override
    public Result<List<Provider>> selectAllProvName() {
        QueryWrapper<Provider> wrapper=new QueryWrapper<>();
        wrapper.eq("status",0);
        List<Provider> providers =providerDao.selectList(wrapper);
        return new Result<>(2000,"查询供应商",providers);
    }
}
